﻿using System;
using System.Collections.Generic;
using System.Text;
using Manso.cBot.Common;
using VhaBot.Net;
using VhaBot.Net.Events;
using System.ComponentModel;
using System.Threading;

namespace Manso.cBot.DefaultCommands
{    
    public class WhoCommand : ICommand
    {
        private readonly ListenToEnum _listenTo;
        private readonly string _command;
        private readonly string _help;
        private readonly string _usage;
        private readonly AccessControlLevel _accessLevel;

        public WhoCommand()
        {
            _listenTo = ListenToEnum.Both;
            _command = "Who";
            _help = "Show information about a player";
            _usage = "who character_name";
            _accessLevel = AccessControlLevel.Basic;
        }

        public ListenToEnum ListenTo
        {
            get { return _listenTo; }
        }

        public string Command
        {
            get { return _command; }
        }

        public string Help
        {
            get { return _help; }
        }

        public string Usage
        {
            get { return _usage; }
        }

        public AccessControlLevel AccessLevel
        {
            get { return _accessLevel; }
        }

        public void ExecuteCommand(string[] args, string executedBy, ListenToEnum listenTo)
        {
            if (args.Length != 1 || args[0].Length == 0)
            {
                cBotContext.Instance.SendPrivateMessage(executedBy, "Argument error. Try help who for usage information.");
                return;
            }
            Who who = new Who();
            FriendStatusEventArgs info = who.WhoIs(args[0]);
            String message = "Character doesn't exists";
            if (info != null)
            {
                message = String.Format("{0} {1} {2} {3}", info.Character, info.Class, info.Level, (info.Online) ? "Online" : "Offline");
            }
            switch (listenTo)
            {
                case ListenToEnum.Guild:                    
                    cBotContext.Instance.SendGuildMessage(message);
                    break;
                case ListenToEnum.Tell:
                    cBotContext.Instance.SendPrivateMessage(executedBy, message);
                    break;             
            }
        }                
    }       
}
